﻿Imports System.Data.SqlClient
Public Class FrmIngreso



    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim Frm1 As New FrmP_Admin
        Dim Frm2 As New FrmP_RMP
        Dim Frm3 As New FrmP_BCF
        Dim Frm4 As New FrmP_Proceso

        Dim cnn As New SqlConnection(My.Settings.INVE_FISHConnectionString)
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader



        cnn.Open()
        cmd = New SqlCommand("sp_Login")
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@usuario", TxtUsuario.Text)
        cmd.Parameters.AddWithValue("@Contrasenia", TxtContrasenia.Text)
        cmd.Connection = cnn
        cmd.ExecuteNonQuery()
        dr = cmd.ExecuteReader


        Dim dt As New DataTable
        dt.Load(dr)

        If dt.Rows.Count = 0 Then

            MessageBox.Show("Usuario y/o contraseña incorrecto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            Dim str_Rol As String = dt.Rows(0).Item(0).ToString


            If str_Rol = "Gerente de Produccion" Then
                MessageBox.Show("Bienvenido al Sistema", "Ingreso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                FrmP_Admin.Show()
                Me.Close()


            ElseIf str_Rol = "Recepcion Materia Prima" Then
                MessageBox.Show("Bienvenido al Sistema", "Ingreso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                FrmP_RMP.Show()
                Me.Close()

            ElseIf str_Rol = "Proceso" Then
                MessageBox.Show("Bienvenido al Sistema", "Ingreso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                FrmP_Proceso.Show()
                Me.Close()

            ElseIf str_Rol = "Cuarto Frio" Then
                MessageBox.Show("Bienvenido al Sistema", "Ingreso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                FrmP_BCF.Show()
                Me.Close()

            End If

        End If
        cnn.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub FrmIngreso_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
